package com.shop.cereshop.agent.param.user;

import com.shop.cereshop.commons.config.RsaProperties;
import com.shop.cereshop.commons.utils.RsaUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import javax.validation.constraints.NotNull;



@Slf4j
@Data
@ApiModel
public class RegisterDTO {

    @ApiModelProperty(value = "验证码",required = true)
    @NotNull(message = "验证码不能为空")
    private String verificationCode;

    @ApiModelProperty(value = "手机号/uuid(需要加密)", required = true)
    @NotNull(message = "手机号不能为空")
    private String phone;


    @ApiModelProperty(value = "密码(需要加密)")
    private String password;

    @ApiModelProperty(value = "邀请码",required = true)
    @NotNull(message = "邀请码不能为空")
    private String inviteCode;


    public RegisterDTO decrypt() throws Exception {
        RegisterDTO res = this;
        try {
            if (this.phone != null) {
                res.setPhone(RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, this.phone));
            }
            if (this.password != null) {
                res.setPassword(RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, this.password));
            }
        } catch (Exception e) {
          log.error("解密失败");
        }
        return res;
    }
}
